K8SPSMDB-1389: don't round up pvc sizes#2341
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates PVC resize logic to avoid rounding/overshoot issues (e.g., storage backends provisioning larger-than-requested PVCs) and adds tests to cover the revised reconciliation behavior.
Changes:
- Stop rounding requested PVC sizes up to GiB during reconciliation and autoscaling calculations.
- Treat PVC resize as finished when capacity is >= requested (not only equal).
- Add unit tests for PVC reconciliation, including external autoscaling/volume expansion combinations.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| pkg/controller/perconaservermongodb/volumes.go | Removes GiB rounding and adjusts resize finish + stale template handling logic. |
| pkg/controller/perconaservermongodb/volume_autoscaling.go | Removes GiB rounding from autoscaling size calculation. |
| pkg/controller/perconaservermongodb/volumes_test.go | Adds new unit tests for reconcilePVCs behavior across resize/shrink/stale-template scenarios. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
12 tasks
Comment on lines
141
to
147
| for _, pvc := range pvcList.Items { | ||
| if !validatePVCName(pvc, sts) { | ||
| continue | ||
| } | ||
|
|
||
| if pvc.Status.Capacity.Storage().Cmp(requested) == 0 { | ||
| if pvc.Status.Capacity.Storage().Cmp(requested) >= 0 { | ||
| updatedPVCs++ |
egegunes
approved these changes
Jun 1, 2026
hors
reviewed
Jun 8, 2026
hors
left a comment
Collaborator
There was a problem hiding this comment.
Do we need to fix go lint?
egegunes
requested changes
Jun 9, 2026
| "k8s.io/apimachinery/pkg/runtime" | ||
| "k8s.io/apimachinery/pkg/types" | ||
| "k8s.io/client-go/kubernetes/scheme" | ||
| clientgoscheme "k8s.io/client-go/kubernetes/scheme" |
egegunes
approved these changes
Jun 10, 2026
hors
approved these changes
Jun 10, 2026
| } | ||
|
|
||
| if pvc.Status.Capacity.Storage().Cmp(requested) == 0 { | ||
| if pvc.Status.Capacity.Storage().Cmp(requested) >= 0 { |
Collaborator
commit: 07f38cc |
mayankshah1607
approved these changes
Jun 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://perconadev.atlassian.net/browse/K8SPSMDB-1389
DESCRIPTION
Problem:
When
volumeSpec.persistentVolumeClaim.resources.requests.storageis set to1.2Gioperator creates a statefulset with the same size, but2GiPVC is created. After updating thecr.yamlto the2Githe operator should recreate the statefulset with the new size, but it tries to update statefulset instead and gets the following error:...update error: StatefulSet.apps "..." is invalid: spec: Forbidden: updates to statefulset spec for fields other than ...Cause:
The storage provisioners may create a
2GiPVC for a1.2Girequest because it allocates storage in larger chunks.The operator logic rounded the requested size to GiB and then checked for an exact match, but the actual PVC may have a larger size than the value from the
cr.yaml.Because of that, after changing the CR to 2Gi, the operator wasn't able to check if PVC resize update is needed and tried to update the StatefulSet template instead.
Solution:
The operator now uses the exact value from
cr.yamland treats the pvc as correct when its actual size is greater than or equal to the requested size.It also checks whether the StatefulSet template still has an old storage value. If the PVC already has enough space but the template is different, the operator deletes and recreates the StatefulSet instead of trying to update it
CHECKLIST
Jira
Needs Doc) and QA (Needs QA)?Tests
compare/*-oc.yml)?Config/Logging/Testability